/*
  Copyright (C) 2011, Kyungjoo Kim
  
  This file is part of LINAL (LINear ALgebra)
  
  All rights reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  Also add information on how to contact you by electronic and paper mail.
  
  
  Kyungjoo Kim
  iamkyungjoo@gmail.com
*/
#include "linal/common.hxx"
#include "linal/util.hxx"

#include "linal/format.hxx"

#include "linal/device/host/operation.hxx"


namespace linal      {
  namespace host   {
    namespace internal {
      int inv_norm1( int uplo, int diag, FLA_Obj &A, FLA_Obj &norm ) {
        return inv_norm1(0.0, uplo, diag, A);
      }
      int inv_norm1( double sample,
                     int uplo, int diag, FLA_Obj &A, FLA_Obj &norm ) {

        LINAL_ERROR_DETAIL( A.get_m() == A.get_n(),
                            "%s\n %s %d\n %s %d\n",
                            LINAL_ERROR_A_SQUARE_MATRIX,
                            "length = ", A.get_m(),
                            "width  = ", A.get_n() );

        int datatype = FLA_Obj_datatype( A );
        int m        = FLA_Obj_length( A );

        linal::Flat_ x, y, z, rho;
        x.create( datatype, m, 1 );
        y.create( datatype, m, 1 );
        z.create( datatype, m, 1 );
        rho.create( linal::get_datatype_real(datatype), 1, 1 );

        // Initial setup.
        if (seed < 0) {
          for (int i=0;i<m;++i)
            x(i,0) = 1.0/(double)m;
        } else {
          FLA_Set(FLA_ZERO, ~x);
          x(seed,0) = 1.0;
        }


        return true;
      }
    }
  }
}

